//
//  ZCinvolvedIconCell.m
//  zctx
//
//  Created by apple on 15/12/29.
//  Copyright © 2015年 sanliang. All rights reserved.
//

#import "ZCinvolvedIconCell.h"

@implementation ZCinvolvedIconCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier cellType:(NSArray *)Array{
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self addIconImgView:Array];
        [self addrightImgViews];
        [self addInfoView];
    }
    return self;
}

- (void)awakeFromNib {
    // Initialization code
}



-(void)addIconImgView:(NSArray *)dataArray{
    
    CGFloat buttonW;
    CGFloat headermarge = 18;
    CGFloat margex = 10;
    CGFloat margey = 0;
    if (IS_IPHONE_5 ||IS_IPHONE_4_OR_LESS) {
        margex = 5;
        buttonW = 25;
        margey = 9.5;
    }else{
        buttonW = 32;
        margex = 10;
        margey = 6;
    }
//    NSLog(@"tag000 = %ld, dataArray = %@",dataArray.count,dataArray);
    
    for (int i = 0 ; i < dataArray.count; i++) {
        
        ZCInvolvedDetailsModelLatestSixSponsors *dict =(ZCInvolvedDetailsModelLatestSixSponsors *) dataArray[i];
        NSInteger index = i % 6;
        NSInteger page = i / 6;
        // 圆角按钮
        CGRect rect = CGRectMake(index * (buttonW+margex)+headermarge,(page  * 100) + margey, buttonW, buttonW);
        UIImageView *btnView = [[UIImageView alloc] initWithFrame:rect];
        btnView.tag = i;
        btnView.layer.cornerRadius = buttonW/2;
        btnView.layer.masksToBounds = YES;
        btnView.backgroundColor = [UIColor orangeColor];
        NSString *imageStr = dict.avatar;
        if (imageStr.length>0) {
            [btnView sd_setImageWithURL:[NSURL URLWithString:imageStr] placeholderImage:[UIImage imageNamed:@"projectdetail_icon"]];
        }else{
            btnView.image = [UIImage imageNamed:@"projectdetail_icon"];
        }
        [self.contentView addSubview:btnView];
    }
}

-(void)addrightImgViews{
    [self.contentView addSubview:self.rightImgView];
    [self.rightImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView.centerY);
        make.height.mas_equalTo(13);
        make.right.equalTo(self.contentView.right).with.offset(-18);
        make.width.mas_equalTo(7);
    }];
}


-(void)addInfoView{

    [self.contentView addSubview:self.labelInfo];
    self.labelInfo.text = @"更多支持者";
    self.labelInfo.textColor = [UIColor colorWithHexString:@"#b2b2b2"];
    self.labelInfo.textAlignment = NSTextAlignmentRight;
    self.labelInfo.font = [UIFont systemFontOfSize:14];
    [self.labelInfo mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView.centerY);
        make.height.mas_equalTo(21);
        make.right.equalTo(self.rightImgView.left).with.offset(-5);
        make.width.mas_equalTo(80);
    }];
}

- (UILabel *)labelInfo {
    if (!_labelInfo) {
        _labelInfo = [[UILabel alloc] init];
        _labelInfo.font = [UIFont systemFontOfSize:15];
        _labelInfo.textAlignment = NSTextAlignmentLeft;
        [_labelInfo setTextColor:[UIColor colorWithHexString:@"000000"]];
    }
    return _labelInfo;
}

- (UIImageView *)rightImgView {
    if (!_rightImgView) {
        _rightImgView = [[UIImageView alloc] init];
        [_rightImgView setImage:[UIImage imageNamed:@"raise_right"]];
    }
    return _rightImgView;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
